package GameMain.Model
{
	
	import GameMain.Game;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.ui.Mouse;
	import flash.utils.getTimer;
	import flash.utils.setTimeout;
	
	import library.SocketData.SocketData;

	public class Entity extends EntityMove
	{
		public static var MAP_STEP_Y:int = 410			//地图调整坐标
		
		public static var ACTION_STAND:int = 1;			//站立
		public static var ACTION_MOVE_FORWARD:int = 2;	//前进
		public static var ACTION_MOVE_BACK:int = 3;		//后退
		public static var ACTION_JUMP:int = 4;			//起跳
		public static var ACTION_NORMAL_ATTACK:int = 5;	//普通攻击
		public static var ACTION_DEAD:int = 6;
		
		
		private var _attackX:Number = 800;					//攻击目标所在位置
		
		private var _attackEffect:Sprite = null;				//攻击效果,临时
		
		private var _playerName:String = "";					//名字
		private var _playerSex:int = 0;						//性别
		private var _playerLevel:int = 0;						//等级
		protected var _playerProfession:int = 0;					//职业
		
		private var _playerHP:int = 100 ;
		private var _playerMaxHP:int = 0;
		private var _playerState:int = 0;
		
		
		
		
		public function Entity()
		{
			this._playerState = ACTION_STAND;
		}
		
		override public function addToParent(_parent:DisplayObjectContainer):void
		{
			super.addToParent(_parent);
		}
		
		public function initModel():void
		{
			this.playAction(ACTION_STAND);
		}
		
		public function setMC(_mc:Sprite,head:Boolean = false):void
		{
			if(head)
			{
				_mc.scaleX = 0.3;
				_mc.scaleY = 0.4;
				_mc.scaleZ = 1.0;
			}
			else
			{
				this.addChild(_mc);
			}
		}
		
		public function setPlayerHP(hp:int):void
		{
			var value:int = this._playerHP - hp;
			this._playerHP = hp;
			if(this._playerHP <= 0)
			{
				
			}
		}
		
		/*设置一个Entity属性*/
		public function initEntityProp(data:SocketData):void
		{
			this._entityID = data.readInt16();
			this._playerName = data.readString();
			this._playerLevel = data.readInt8();
			this._playerSex = data.readInt8();
			this._playerProfession = data.readInt8();
		}
		
		//进入游戏中心重载数据
		public function initGameProp(entID:int,data:SocketData):void
		{
			this._entityID = entID;
			var _x:int = data.readInt16();
			var _y:int = data.readInt16();
			this._playerLevel = data.readInt8();
			this.setPosition(_x,_y);
			this._playerSex = data.readInt8();
			this._playerProfession = data.readInt8();
			this._playerName = data.readString();
		}
		
		
		public function setPlayerName(txt:String):void
		{
			this._playerName = txt;
		}
		
		public function get playerName():String
		{
			return this._playerName;
		}
		
		public function get playerLevel():int
		{
			return this._playerLevel;
		}
		
		override public function destroy():void
		{
			super.destroy();
		}
		
		
		override public function setPosition(_x:Number,_y:Number = 0):void
		{
			super.setPosition(_x,_y); 
		}
		
		//播放动作
		public function playAction(actionState:int):void
		{
			this._playerState = actionState;
			switch(actionState)
			{
				case ACTION_STAND:
					this.playActionStand()
					break;
				case ACTION_MOVE_BACK:
					this.playActionMoveBackward();
					break;
				case ACTION_MOVE_FORWARD:
					this.playActionMoveForward();
					break;
				case ACTION_JUMP:
					this.playActionJump();
					break;
				case ACTION_NORMAL_ATTACK:
					this.playActionNormalAttack();
					break;
				case ACTION_DEAD:
					this.playActionDead();
					break
					
			}
		}
		
		protected function playActionStand():void
		{
			
		}
		
		
		protected function playActionMoveForward():void
		{
			
		}
		
		protected function playActionMoveBackward():void
		{
			
		}
		
		protected function playActionJump():void
		{
			
		}
		
		protected function playActionNormalAttack():void
		{
			
		}
		
		protected function playActionDead():void
		{
			
		}
	}
}